<template>
	<view class="upload_info">
		<view class="upload_img" v-for="(item, index) of imgs" :key="index">
			<image :src="item" mode="aspectFill"></image>
			<text class="delete" @click="onDeleteImg(index)"></text>
		</view>
		<view class="upload_img upload" @click="onImgsUpload" v-if="imgs.length < maxCount">
			<image class="upload_img_img" src="../../static/img/common/has_img_icon.png" mode=""></image>
			<view class="upload_img_text">上传图片</view>
		</view>
	</view>
</template>

<script>
	export default {
		data () {
			return {
			}
		},
		props: {
			uploadMax: { // 5M
				type: [Number, String],
				default: 5
			},
			maxCount: {
				type: [Number, String],
				default: 9
			},
			mode: { // 和 min-action-sheet组件配合
				type: [Number, String],
				default: 1
			},
			imgs: {
				type: Array,
				default() {
					return []
				}
			}
		},
		onLoad() {
			console.log('inner mode', this.mode)
		},
		methods: {
			onImgsUpload() {
				this.$emit('chooseUpload')
			}
		}
	}
</script>

<style scoped lang="scss">
	.upload_info {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		padding-bottom: 10upx;
	
		.upload_img {
			width: 200upx;
			height: 200upx;
			background-color: #ffffff;
			border-radius: 4upx;
			margin-right: 16upx;
			margin-bottom: 16upx;
			overflow: hidden;
			position: relative;
	
			&:nth-child(3n) {
				margin-right: 0;
			}
	
			image {
				width: 100%;
				height: 100%;
			}
	
			.delete {
				position: absolute;
				top: 0upx;
				right: 0upx;
				width: 44upx;
				height: 44upx;
				background-image: url('../../static/img/common/icon_delete.png');
				background-position: center center;
				background-repeat: no-repeat;
				background-size: 100% 100%;
			}
	
			&.upload {
				text-align: center;
				border: 1upx dashed #b2b2b2;
				display: flex;
				flex-flow: column nowrap;
				justify-content: center;
				align-items: center;
			}
			.upload_img_img {
				width: 80rpx;
				height: 80rpx;
				padding-bottom: 10rpx;
			}
			.upload_img_text {
				color: #ccc;
			}
		}
	}
</style>
